#include<iostream>
#include<sys/types.h>
#include<unistd.h>
#include<signal.h>

using std::cout;
using std::endl;
using std::cerr;
int cnt=0;
void handler(int signum)
{
    cout<<"I am a process!my pid::"<<getpid()<<"I catch a signal,its number::"<<signum<<"Time::"<<cnt<<endl;
}

void showSigals(sigset_t *signals)
{
    int sig=1;
    for(sig=1;sig<=31;sig++)
    {
        if(sigismember(signals,sig))
        {
            cout<<"1";
        }
        else
        {
            cout<<"0";
        }
    }
    cout<<endl;
}
int main()
{
    int count=0;
    cout<<"Process pid::"<<getpid()<<endl;

    sigset_t sigset, osigset;
    sigemptyset(&sigset);
    sigemptyset(&osigset);
    
    int sig=1;
    for(sig=1;sig<=31;sig++)
    {
        sigaddset(&sigset,sig);
        signal(sig,handler);
    }
    sigprocmask(SIG_BLOCK,&sigset,&osigset);

    sigset_t pendings;
    while(true)
    {
        sigemptyset(&pendings);
        sigpending(&pendings);
        showSigals(&pendings);
        sleep(1);
        count++;
        if(count==15)
        {
            sigemptyset(&sigset);
            sigaddset(&sigset,2);
            sigaddset(&sigset,3);
            sigaddset(&sigset,4);
            sigaddset(&sigset,5);
            sigprocmask(SIG_UNBLOCK,&sigset,&osigset);

        }
    }


    return 0;
}
